package project.service.impl;

import project.dao.UserDAO;
import project.dao.impl.UserDAOImpl;
import project.pojo.User;
import project.service.UserService;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author d11yu
 */
public class UserServiceImpl implements UserService {
    private UserDAO userDAO = new UserDAOImpl();

    /**
     * 注册用户
     *
     * @param user
     */
    @Override
    public User register( User user) throws SQLException {
        return userDAO.insertUser( user);
    }

    /**
     * 登录
     *
     * @param user
     */
    @Override
    public User login( User user) throws SQLException {
        return userDAO.queryUserByUsernameAndPassword( user.getUsername(), user.getPassword());
    }

    /**
     * 检查用户名是否存在
     *
     * @param username
     * @return
     */
    @Override
    public boolean exists( String username) throws SQLException {
        if (userDAO.queryUserByUsername( username) == null) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public boolean exists( User user) throws SQLException {
        if (userDAO.queryUserByUsername( user.getUsername()) == null) {
            return false;
        } else {
            return true;
        }
    }
}
